#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <stack>

using namespace std;

class Solution
{
public:
    string removeDuplicates(string s)
    {
        stack<int> st;
        int n = s.size();
        for (int i = 0; i < n; i++)
        {
            if (st.empty() || s[i] != st.top())
            {
                st.push(s[i]);
            }
            else
            {
                st.pop();
            }
        }
        string ret;
        while (!st.empty())
        {
            ret += st.top();
            st.pop();
        }
        reverse(ret.begin(), ret.end());
        return ret;
    }
};

int main()
{
    Solution s;
    string que = "abbaca";
    cout << s.removeDuplicates(que) << endl;
    return 0;
}